package com.proton.carepatchtemp.database.daomanager;

import com.proton.carepatchtemp.database.gen.HealthTipDao;
import com.proton.carepatchtemp.database.table.HealthTip;

import java.util.List;

/**
 * Created by MoonlightSW on 2017/2/22.
 */

public class HealthTipManager {
    private HealthTipDao mTipDao;

    public HealthTipManager() {
        mTipDao = GreenDaoManager.get().getmDaoSession().getHealthTipDao();
    }

    public static void insertOrReplaceInTx(List<HealthTip> healthTips) {
        getTipDao().insertOrReplaceInTx(healthTips);
    }

    public static List<HealthTip> getAll() {
        return getTipDao().queryBuilder().orderDesc(HealthTipDao.Properties.Time).list();
    }

    public static List<HealthTip> getFromId(Long id) {
        return getTipDao().queryBuilder().where(HealthTipDao.Properties.Id.gt(id)).orderDesc(HealthTipDao.Properties.Time).list();
    }

    public static List<HealthTip> getBoforeList(Long time) {
        return getTipDao().queryBuilder().where(HealthTipDao.Properties.Time.lt(time)).orderDesc(HealthTipDao.Properties.Time).list();
    }

    public static HealthTip getById(Long id) {
        return getTipDao().load(id);
    }

    public static void deleteAll() {
        getTipDao().deleteAll();
    }

    private static HealthTipDao getTipDao() {
        return GreenDaoManager.get().getmDaoSession().getHealthTipDao();
    }

}
